package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.common.exceptios.LyException;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 虎哥
 */
@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper, SpecParam> implements SpecParamService {
    @Override
    public List<SpecParamDTO> queryParams(Long gid, Long cid, Boolean searching) {
        // 健壮性判断
        if(cid == null && gid == null){
            // 说明没有查询条件，非常危险，不允许
            throw new LyException(400, "cid或gid参数至少要有一个");
        }
        // 查询
        List<SpecParam> list = query()
                .eq(cid != null, "category_id", cid)
                .eq(gid != null, "group_id", gid)
                .eq(searching != null, "searching", searching)
                .list();
        return SpecParamDTO.convertEntityList(list);
    }
}
